package com.myproject.mall.goods.controller;

import com.myproject.mall.common.result.HttpResult;
import com.myproject.mall.domain.vo.GoodsVO;
import com.myproject.mall.goods.service.IRecommendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品推荐接口")
@RestController
@RequestMapping("/api/recommend")
@RequiredArgsConstructor
public class RecommendController {
    private final IRecommendService recommendService;

    @Operation(summary = "获取商品推荐")
    @GetMapping("/get/recommend")
    public HttpResult<List<GoodsVO>> getRecommend(@RequestParam String userId) {
        return HttpResult.success(recommendService.recommend(userId));
    }

    @Operation(summary = "商品浏览记录")
    @PostMapping("/add/viewHistory")
    public HttpResult<Void> addViewHistory(@RequestParam Long goodsId) {
        recommendService.addViewHistory(goodsId);
        return null;
    }

    @Operation(summary = "获取浏览记录")
    @GetMapping("/get/viewHistory")
    public HttpResult<List<GoodsVO>> getViewHistory() {
        List<GoodsVO> viewHistory = recommendService.getViewHistory();
        return HttpResult.success(viewHistory);
    }

    @Operation(summary = "1日热销")
    @GetMapping("/get/dayHot")
    public HttpResult<List<GoodsVO>> getWeekHot() {
        List<GoodsVO> weekHot = recommendService.getHot(7, 10);
        return HttpResult.success(weekHot);
    }

    @Operation(summary = "1周热销")
    @GetMapping("/get/weekHot")
    public HttpResult<List<GoodsVO>> getMonthHot() {
        List<GoodsVO> monthHot = recommendService.getHot(7, 10);
        return HttpResult.success(monthHot);
    }
}
